package com.zm.tools.util.core;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;

import static java.lang.System.out;

/**
 * 文件与字节数据，输出流的转换
 * @author zoum
 * @create 2018/6/6 18:12
 */
public class FileReadUtil {

    public static void read(String path) throws Exception{
        File file = new File(path);
        if (file.exists()){

            BufferedReader reader = new BufferedReader(new FileReader(file));
            BufferedWriter write = new BufferedWriter(new FileWriter(file.getPath()+".sql"));
            String line="";
            while ((line=reader.readLine()) != null){
                String []lineSplit = line.split(" ");
                if (lineSplit.length > 1){
                    write.write("update pay_record set cash_deductible_amount=" + BigDecimal.valueOf(Double.valueOf(lineSplit[1])).divide(BigDecimal.valueOf(100D), 2, RoundingMode.HALF_UP) + " where out_trade_no=" + lineSplit[0] +";\n");
                }
            }

            reader.close();
            write.close();
        }
    }

    public static void main(String[]args) throws Exception{
        read("C:\\Users\\Administrator\\Desktop\\工作\\会员付费\\payment.temp1.csv");
    }
}
